import CryptoJS from "crypto-js";

const AES = {
    encrypt(data, secretKey, iv) {
        const result = CryptoJS.AES.encrypt(
                data,
                CryptoJS.enc.Utf8.parse(secretKey),
                {
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7,
                    iv: CryptoJS.enc.Utf8.parse(iv),
                }
        );
        return result.toString()
    },
    decrypt(cipher, secretKey, iv) {
        const result = CryptoJS.AES.decrypt(
                cipher,
                CryptoJS.enc.Utf8.parse(secretKey),
                {
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7,
                    iv: CryptoJS.enc.Utf8.parse(iv),
                }
        );
        return CryptoJS.enc.Utf8.stringify(result)
    },
}
const Base64 = {
    encrypt(data) {
        return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))
    },
    decrypt(cipher) {
        return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8)
    }
}

export default {AES, Base64}
